package com.colin.service.impl;

import com.colin.mapper.ShangChuanDateMapper;
import com.colin.pojo.PageBean;
import com.colin.pojo.ShangChuanData;
import com.colin.service.ShangChuanDateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ShangChuanDateServiceImpl implements ShangChuanDateService {
    @Autowired
    ShangChuanDateMapper shangChuanDateMapper;

    @Override
    public PageBean<ShangChuanData> findBlogByPageUplodData (Integer currentPage) {
        int rows = 3;
        PageBean<ShangChuanData> pageBean = new PageBean<>();
        pageBean.setRows(rows);
        pageBean.setCurrentPage(currentPage);
        int totalCount = shangChuanDateMapper.findTotalCount();
        pageBean.setTotalCount(totalCount);
        int a = (pageBean.getCurrentPage() - 1);
        int b = pageBean.getRows();
        int start = a * b;
        List<ShangChuanData> list = shangChuanDateMapper.findByPage(start, b);
        pageBean.setList(list);
        int totalPage = totalCount % b == 0 ? totalCount / b : totalCount / b + 1;
        pageBean.setTotalPage(totalPage);
        return pageBean;
    }

    @Override
    public ShangChuanData find (Integer id) {
        return shangChuanDateMapper.find(id);
    }

    @Override
    public void insert (ShangChuanData shangChuanData) {
        shangChuanDateMapper.insert(shangChuanData);
    }

    @Override
    public int count () {
        return shangChuanDateMapper.count();
    }


}
